---
layout: "default"
title: "Float"
description: "Swift documentation for struct 'Float'."
keywords: "Float,struct,swift,documentation,abs,advancedBy,distanceTo,encode,getMirror,NaN,description,floatingPointClass,hashValue,infinity,isFinite,isInfinite,isNaN,isNormal,isSignMinus,isSignaling,isSubnormal,isZero,quietNaN"
root: "/v1.2"
---

<div class="intro-declaration"><code class="language-swift">struct Float</code></div>


<table class="standard">
<tr>
<th id="inheritance">Inheritance</th>
<td>
<code class="inherits">AbsoluteValuable, CVarArgType, Comparable, Equatable, FloatLiteralConvertible, FloatingPointType, Hashable, IntegerLiteralConvertible, Printable, Reflectable, SignedNumberType, Strideable, _CVarArgPassedAsDouble, _Comparable, _SignedNumberType, _Strideable</code>
<span class="viz"><a href="hierarchy/">View Protocol Hierarchy &rarr;</a></span>
</td>
</tr>



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init">
<a class="toggle-link" data-toggle="collapse" href="#comment-init">init()</a><div class="comment collapse" id="comment-init"><div class="p">
    <p>Create an instance initialized to zero.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init()</code>

    </div></div>
</div>
<div class="declaration" id="init_-double">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-double">init(<wbr>_: Double)</a><div class="comment collapse" id="comment-init_-double"><div class="p">
    <p>Construct an instance that approximates <code>other</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ other: Double)</code>

    </div></div>
</div>
<div class="declaration" id="init_-float">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-float">init(<wbr>_: Float)</a><div class="comment collapse" id="comment-init_-float"><div class="p">
    <p>Create an instance initialized to <code>value</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ value: Float)</code>

    </div></div>
</div>
<div class="declaration" id="init_-float80">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-float80">init(<wbr>_: Float80)</a><div class="comment collapse" id="comment-init_-float80"><div class="p">
    <p>Construct an instance that approximates <code>other</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ other: Float80)</code>

    </div></div>
</div>
<div class="declaration" id="init_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-int">init(<wbr>_: Int)</a><div class="comment collapse" id="comment-init_-int"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: Int)</code>

    </div></div>
</div>
<div class="declaration" id="init_-int8">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-int8">init(<wbr>_: Int8)</a><div class="comment collapse" id="comment-init_-int8"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: Int8)</code>

    </div></div>
</div>
<div class="declaration" id="init_-int16">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-int16">init(<wbr>_: Int16)</a><div class="comment collapse" id="comment-init_-int16"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: Int16)</code>

    </div></div>
</div>
<div class="declaration" id="init_-int32">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-int32">init(<wbr>_: Int32)</a><div class="comment collapse" id="comment-init_-int32"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: Int32)</code>

    </div></div>
</div>
<div class="declaration" id="init_-int64">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-int64">init(<wbr>_: Int64)</a><div class="comment collapse" id="comment-init_-int64"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: Int64)</code>

    </div></div>
</div>
<div class="declaration" id="init_-uint">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-uint">init(<wbr>_: UInt)</a><div class="comment collapse" id="comment-init_-uint"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: UInt)</code>

    </div></div>
</div>
<div class="declaration" id="init_-uint8">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-uint8">init(<wbr>_: UInt8)</a><div class="comment collapse" id="comment-init_-uint8"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: UInt8)</code>

    </div></div>
</div>
<div class="declaration" id="init_-uint16">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-uint16">init(<wbr>_: UInt16)</a><div class="comment collapse" id="comment-init_-uint16"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: UInt16)</code>

    </div></div>
</div>
<div class="declaration" id="init_-uint32">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-uint32">init(<wbr>_: UInt32)</a><div class="comment collapse" id="comment-init_-uint32"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: UInt32)</code>

    </div></div>
</div>
<div class="declaration" id="init_-uint64">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-uint64">init(<wbr>_: UInt64)</a><div class="comment collapse" id="comment-init_-uint64"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ v: UInt64)</code>

    </div></div>
</div>
<div class="declaration" id="init-bits_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-bits_">init(<wbr>_bits:)</a><div class="comment collapse" id="comment-init-bits_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_bits v: Builtin.FPIEEE32)</code>

    </div></div>
</div>
<div class="declaration" id="init-builtinfloatliteral_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-builtinfloatliteral_">init(<wbr>_builtinFloatLiteral:)</a><div class="comment collapse" id="comment-init-builtinfloatliteral_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_builtinFloatLiteral value: Builtin.FPIEEE80)</code>

    </div></div>
</div>
<div class="declaration" id="init-builtinintegerliteral_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-builtinintegerliteral_">init(<wbr>_builtinIntegerLiteral:)</a><div class="comment collapse" id="comment-init-builtinintegerliteral_"><div class="p">
    

    <h4>Declaration</h4>    
    <code class="language-swift">init(_builtinIntegerLiteral value: Builtin.Int2048)</code>

    </div></div>
</div>
<div class="declaration" id="init-floatliteral_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-floatliteral_">init(<wbr>floatLiteral:)</a><div class="comment collapse" id="comment-init-floatliteral_"><div class="p">
    <p>Create an instance initialized to <code>value</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(floatLiteral value: Float)</code>

    </div></div>
</div>
<div class="declaration" id="init-integerliteral_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init-integerliteral_">init(<wbr>integerLiteral:)</a><div class="comment collapse" id="comment-init-integerliteral_"><div class="p">
    <p>Create an instance initialized to <code>value</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(integerLiteral value: Int64)</code>

    </div></div>
</div>

<h3>Static Variables</h3>
<div class="declaration" id="static-var-nan_-float">
<a class="toggle-link" data-toggle="collapse" href="#comment-static-var-nan_-float">static var NaN: Float</a><div class="comment collapse" id="comment-static-var-nan_-float"><div class="p">
    <p>A quiet NaN.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">static var NaN: Float { get }</code>

    </div></div>
</div>
<div class="declaration" id="static-var-infinity_-float">
<a class="toggle-link" data-toggle="collapse" href="#comment-static-var-infinity_-float">static var infinity: Float</a><div class="comment collapse" id="comment-static-var-infinity_-float"><div class="p">
    <p>The positive infinity.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">static var infinity: Float { get }</code>

    </div></div>
</div>
<div class="declaration" id="static-var-quietnan_-float">
<a class="toggle-link" data-toggle="collapse" href="#comment-static-var-quietnan_-float">static var quietNaN: Float</a><div class="comment collapse" id="comment-static-var-quietnan_-float"><div class="p">
    <p>A quiet NaN.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">static var quietNaN: Float { get }</code>

    </div></div>
</div>

<h3>Instance Variables</h3>
<div class="declaration" id="var-description_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-description_-string">var description: String</a><div class="comment collapse" id="comment-var-description_-string"><div class="p">
    <p>A textual representation of <code>self</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var description: String { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-floatingpointclass_-floatingpointclassification">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-floatingpointclass_-floatingpointclassification">var floatingPointClass: FloatingPointClassification</a><div class="comment collapse" id="comment-var-floatingpointclass_-floatingpointclassification"><div class="p">
    <p>The IEEE 754 &quot;class&quot; of this type.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var floatingPointClass: FloatingPointClassification { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-hashvalue_-int">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-hashvalue_-int">var hashValue: Int</a><div class="comment collapse" id="comment-var-hashvalue_-int"><div class="p">
    <p>The hash value.</p>

<p><strong>Axiom:</strong> <code>x == y</code> implies <code>x.hashValue == y.hashValue</code></p>

<p><strong>Note:</strong> the hash value is not guaranteed to be stable across
different invocations of the same program.  Do not persist the
hash value across program runs.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var hashValue: Int { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-isfinite_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-isfinite_-bool">var isFinite: Bool</a><div class="comment collapse" id="comment-var-isfinite_-bool"><div class="p">
    <p><code>true</code> iff <code>self</code> is zero, subnormal, or normal (not infinity
or NaN).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var isFinite: Bool { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-isinfinite_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-isinfinite_-bool">var isInfinite: Bool</a><div class="comment collapse" id="comment-var-isinfinite_-bool"><div class="p">
    <p><code>true</code> iff <code>self</code> is infinity.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var isInfinite: Bool { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-isnan_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-isnan_-bool">var isNaN: Bool</a><div class="comment collapse" id="comment-var-isnan_-bool"><div class="p">
    <p><code>true</code> iff <code>self</code> is NaN.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var isNaN: Bool { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-isnormal_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-isnormal_-bool">var isNormal: Bool</a><div class="comment collapse" id="comment-var-isnormal_-bool"><div class="p">
    <p><code>true</code> iff <code>self</code> is normal (not zero, subnormal, infinity, or
NaN).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var isNormal: Bool { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-issignminus_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-issignminus_-bool">var isSignMinus: Bool</a><div class="comment collapse" id="comment-var-issignminus_-bool"><div class="p">
    <p><code>true</code> iff <code>self</code> is negative</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var isSignMinus: Bool { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-issignaling_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-issignaling_-bool">var isSignaling: Bool</a><div class="comment collapse" id="comment-var-issignaling_-bool"><div class="p">
    <p><code>true</code> iff <code>self</code> is a signaling NaN.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var isSignaling: Bool { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-issubnormal_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-issubnormal_-bool">var isSubnormal: Bool</a><div class="comment collapse" id="comment-var-issubnormal_-bool"><div class="p">
    <p><code>true</code> iff <code>self</code> is subnormal.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var isSubnormal: Bool { get }</code>

    </div></div>
</div>
<div class="declaration" id="var-iszero_-bool">
<a class="toggle-link" data-toggle="collapse" href="#comment-var-iszero_-bool">var isZero: Bool</a><div class="comment collapse" id="comment-var-iszero_-bool"><div class="p">
    <p><code>true</code> iff <code>self</code> is +0.0 or -0.0.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">var isZero: Bool { get }</code>

    </div></div>
</div>


<h3>Static Methods</h3>
<div class="declaration" id="func-abs_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-abs_">static func abs(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-abs_"><div class="p">
    <p>Returns the absolute value of <code>x</code></p>

    <h4>Declaration</h4>    
    <code class="language-swift">static func abs(x: Float) -&gt; Float</code>
    
    
</div></div>
</div>

<h3>Instance Methods</h3>
<div class="declaration" id="func-advancedby_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-advancedby_">func advancedBy(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-advancedby_"><div class="p">
    <p>Returns a <code>Self</code> <code>x</code> such that <code>self.distanceTo(x)</code> approximates
<code>n</code>.</p>

<p>Complexity: O(1).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func advancedBy(amount: Float) -&gt; Float</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-distanceto_">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-distanceto_">func distanceTo(<wbr>_:)</a>
        
<div class="comment collapse" id="comment-func-distanceto_"><div class="p">
    <p>Returns a stride <code>x</code> such that <code>self.advancedBy(x)</code> approximates
<code>other</code>.</p>

<p>Complexity: O(1).</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func distanceTo(other: Float) -&gt; Float</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-encode">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-encode">func encode()</a>
        
<div class="comment collapse" id="comment-func-encode"><div class="p">
    <p>Transform <code>self</code> into a series of machine words that can be
appropriately interpreted by C varargs</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func encode() -&gt; [Word]</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-getmirror">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-getmirror">func getMirror()</a>
        
<div class="comment collapse" id="comment-func-getmirror"><div class="p">
    <p>Returns a mirror that reflects <code>self</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func getMirror() -&gt; MirrorType</code>
    
    
</div></div>
</div>


